// Copyright (c) 2002 HTHK
//******************************************************************/
//Modification History
//******************************************************************/
//CR log no 1266: By Ploy Li on 2004-04-27
//******************************************************************/

package admin.options;

import com.ffpc.html.Options;

import java.util.ArrayList;
import java.sql.Connection;

import admin.system.role.*;

/**
 * A Class class.
 * <P>
 * @author HTHK
 */
public class RoleOptions
  extends Options
{

  /**
   * Constructor
   */
  public RoleOptions() {
      this.load();
  }

  @Override
protected ArrayList createOptions(Connection con)
    throws Exception
  {
      ArrayList options = new ArrayList();
      RoleBean role = RoleProcess.createBean();
      role.setRole_id("");
      RoleBean[] roles = RoleProcess.find(con,role);
      for (int i=0; i<roles.length; i++)
      {
          Options.Option option
          = new Options.Option( roles[i].getRole_id(),
                                roles[i].getRole_id());
          options.add(i,option);
      }
      return options;
  }


//---------Add by poly, CR log no 1266---------------

	public String getMultiOptions(String[] value)
	{
		StringBuffer htmlOptions = new StringBuffer();
		for (int i=0; this.options!=null && i<this.options.size(); i++)
		{
			Option option = (Option)options.get(i);
			
			boolean selected = false;
			for(int j = 0; j < value.length; j++)
			{
				if (value!=null && value.length!=0 && option.getValue().equals(value[j]))
			  	{
					selected = true;
			  	}
			}
			htmlOptions.append("   <option value=\"").append(option.getValue()).append("\"").append(selected?" selected ":" ")
					.append(" >").append(option.getDescription()).append("</option>\n");
		}
		return htmlOptions.toString();
	}
	
	public String getSingleOptions(String value)
	{
		StringBuffer htmlOptions = new StringBuffer();
		for (int i=0; this.options!=null && i<this.options.size(); i++)
		{
			Option option = (Option)options.get(i);
			
			boolean selected = false;
			if (value!=null && value.length()!=0 && option.getValue().equals(value))
			  	selected = true;
			htmlOptions.append("   <option value=\"").append(option.getValue()).append("\"").append(selected?" selected ":" ")
					.append(" >").append(option.getDescription()).append("</option>\n");
		}
		return htmlOptions.toString();
	}
	
//----------End by poly-----------

}

